<html>
<script type="text/javascript">
function shellSort(array) {
    function swap(array, i, k) {
        var temp = array[i];
        array[i] = array[k];
        array[k] = temp;
    }
    var length = array.length,
        gap = Math.floor(length / 2);
    while (gap > 0) {
    	console.log("Current gap changed to be: " + gap);
        for (var i = gap; i < length; i++) {
        	console.log( "in current loop, i = " + i + " gap: " + gap);
            for (var j = i; 0 < j; j -= gap) {
            	console.log("in current loop, gap is fixed as: " + gap + " current j: " + j);
            	var left = j - gap;
            	console.log(" trying to evaluate left: " + left + " right: " + j);
            	var abapLeft = left + 1;
            	var abapRight = j + 1;
            	console.log(" the corresponding ABAP index, LEFT: " + abapLeft + " RIGHT: " + abapRight);
            	console.log(" array[left]: " + array[left] + " array[right]: " + array[j]);
                if (array[j - gap] > array[j]) {
                    swap(array, j - gap, j);
                } else {
                    break;
                }
            }
        }
        gap = Math.floor(gap / 2);
    }
    return array;
}
var input = [9,4,1,2,3,4,5];
var result = shellSort(input);
debugger;
</script>
</html>